package Bondarenko.algorithm.gen;

import Bondarenko.algorithm.calc.PPN;
import Bondarenko.algorithm.calc.RetString;
import Bondarenko.algorithm.calc.StrToArr;


public class Genome implements Comparable<Genome> {
   final String str;
   int fitness = 0;
   
   public Genome(String str) {
	   this.str = str;
	   int fitness = 0;
	   for (int j=0; j<str.length();j++){
		   fitness =  Math.abs(PPN.eval(RetString.retString(GACrossingString.ARRAY, StrToArr.STA(str))) - GACrossingString.TARGET);
	   }
	   this.fitness = fitness;
   }
   
   public int compareTo(Genome o)  {
	   return  (int) (fitness - o.fitness);
   }
   
   public String toString(){
	 return  " " +RetString.retString(GACrossingString.ARRAY, StrToArr.STA(str)) + " = "+PPN.eval(RetString.retString(GACrossingString.ARRAY, StrToArr.STA(str)))+" Error: "+ (double) (fitness * 100)/GACrossingString.TARGET +"%";
	
   }
}